/**
 * 封装发送ajax请求
 * */
 import config from './config.js'
 export default (url,data={},method='GET') => {
	 return new Promise((resolve,reject) => {
		 wx.request({
		 		 url: config.host + url,
		 		 data,
		 		 method,
				 header: {
					 cookie: wx.getStorageSync('cookies') ? JSON.parse(wx.getStorageSync('cookies')).find(item => item.indexOf('MUSIC_U') !== -1) : ''
				 },
		 		 success(res) {
					 //判断如果登录接口就存储cookie，因为某些请求要登陆后才能发送
					 if (data.isLogin) {
						 wx.setStorage({
							 key: 'cookies',
							 data: JSON.stringify(res.cookies)
						 })
					 }
		 		 	resolve(res.data)
		 		 },
		 		 fail(err) {
		 		 	reject(err)
		 		 }
		 })
	 })
	 
 }